/*
2021-11-9
https://leetcode-cn.com/problems/minimized-maximum-of-products-distributed-to-any-store/
*/
class Solution {
public:
    int minimizedMaximum(int n, vector<int>& quantities) {
        int l=1,r=2e5;
        for(auto t:quantities) r=max(r,t);
        while(l<r)
        {
            int mid=(l+r)>>1;
            if(check(mid,quantities,n)) r=mid;
            else l=mid+1;
        }
        return l;
    }
    bool check(int x,vector<int>& quantities,int n)
        {
            int cnt=0;
            for(auto temp:quantities)
                cnt+=(x+temp-1)/x;
            return cnt<=n;
        }
};
